package org.dwpd.mapper.message;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.dwpd.domain.message.Message;
import org.dwpd.domain.message.MessageInfo;
import org.dwpd.domain.inbox.UserMessageResponse;

import java.util.List;

@Mapper
public interface MessageMapper {


    int addMessage(Message message);

//    @Select("select message_id, user_id, user_name, start_point, end_point, start_time, people_num, " +
//            "message_content, url, accomplish_flag, over_time_flag, create_time, update_time " +
//            "from message where user_id = #{id} and delete_flag = 0 order by accomplish_flag")
    List<Message> selectAllMessageById(Integer id);

//    @Select("select message_id, user_id, start_point, end_point, start_time, people_num, " +
//            "message_content, url, accomplish_flag, over_time_flag, create_time, update_time " +
//            "from message where message_id = #{messageId} and delete_flag = 0")
    Message selectMessageDetailById(Integer messageId);

    @Update("update message set accomplish_flag = 1 where message_id = #{messageId} and lock_flag = 1")
    Integer updateAccomplish(Integer messageId);

    @Update("update message set delete_flag = 1 where message_id = #{messageId}")
    void deleteMessage(Integer messageId);

    Integer updateMessage(Message message);

    @Select("select message_id from message where user_id = #{userId} and NOW() > date_add(start_time, INTERVAL 24 HOUR)")
    List<Integer> selectMessageOverTime(Integer userId);

    Integer updateMessageOverTime(List<Integer> ids);

//    @Select("select message_id, user_id, start_point, end_point, start_time, people_num, " +
//            "message_content, url, accomplish_flag, over_time_flag, create_time, update_time " +
//            "from message where delete_flag = 0")
    List<Message> selectAllMessage();

//    @Select("select message_id, user_id, start_point, end_point, start_time, people_num, " +
//            "message_content, url, accomplish_flag, over_time_flag, create_time, update_time " +
//            "from message where delete_flag = 0 order by create_time")
    List<Message> selectAllNewCreateMessage();

//    @Select("select message_id, user_id, start_point, end_point, start_time, people_num, " +
//            "message_content, url, accomplish_flag, over_time_flag, create_time, update_time " +
//            "from message where delete_flag = 0 and accomplish_flag = 0 and over_time_flag = 0 ")
    List<Message> selectAllNotAccomplishMessage();

    void addRequestMessage(UserMessageResponse resp);

    MessageInfo getMessageDetailById(Integer messageId);

    Integer updateAgree(Integer userId, Integer messageId);

    Integer updateReject(Integer userId, Integer messageId);

    void addAgreeMessage(UserMessageResponse resp);

    void addRejectMessage(UserMessageResponse resp);

    Integer lockMessage(Integer messageId, Integer userId);

    Integer addLockUserMessage(Integer messageId, Integer userId, Integer peopleNum, String peopleList);

    List<MessageInfo> getMessageByIds(List<Integer> ids);

    Integer updateMessageAccomplish(List<Integer> ids);

    List<Integer> selectAllOverTimeTaskIds();

    void addInformMessage(UserMessageResponse resp);

    String getOnSeatUsersByMessageId(Integer messageId);

    Integer getUserIdByMessageId(Integer messageId);
}
